<?php
/**
 * 企业用户管理
 * gemj
 */
if(!defined("SYSTEM_TIME")){
	define("SYSTEM_TIME", isset ( $_SERVER ['REQUEST_TIME'] ) ? $_SERVER ['REQUEST_TIME'] : time ());
}
class Libs_EForm
{
	public static function saveEFormBook(array $param){
		$eid  =  !empty($param['eid']) ? $param['eid'] : 0;

		$default_book = array(
				"edu"=>0,
				"lang"=>0,
				"project"=>0,
				"practice"=>0,
				"offer"=>0,
				"cert"=>0,
				"training"=>0,
				"position"=>0,
				"it"=>0,
				"schoolaward"=>0,
				"other"=>0,
				"photo"=>0
				);

		$book = !empty($param['book']) ? $param['book'] : array();
		$book = array_merge($default_book,$book);

		$db = Db_Resume::instance();

		if(empty($eid)){
			return false;
		}

		$q_sql = "select eid from e_resume_areapos where eid=".$eid;
		$q_eid = $db->getOne($q_sql);

		$change_str = "";
		if(!empty($q_eid)){
			foreach($book as $key=>$val){
				$change_str .= " $key=$val,";
			}
			$change_str = rtrim($change_str,",");
			$sql = "update e_resume_areapos set {$change_str} where eid=".$eid;
		}else{
			$change_str = implode(",",$book);
			$sql = "insert into e_resume_areapos(eid, edu, lang, project, practice, offer, cert, training, position, it, schoolaward, other, photo) values ({$eid}, {$change_str})";
		}

		$re = $db->query($sql);

		return $re;
	}	


	public static function getEFormBook($eid){
		$db = Db_Resume::instance();

		$sql = "select edu, lang, project, practice, offer, cert, training, position, it, schoolaward, other, photo from e_resume_areapos where eid=".$eid;
		$result = $db->getRow($sql);

		if(empty($result)){
			$result = array(
					"edu"=>1,
					"lang"=>1,
					"project"=>1,
					"practice"=>1,
					"offer"=>1,
					"cert"=>1,
					"training"=>1,
					"position"=>1,
					"it"=>1,
					"schoolaward"=>1,
					"other"=>1,
					"photo"=>1
				       );

		}

		return $result;
	}

	public static function changeEResumeState(array $param){
		$eid = !empty($param['eid']) ? $param['eid'] : 0;
		$jobid = !empty($param['jobid']) ? $param['jobid']: 0;
		$uid = !empty($param['uid']) ? $param['uid'] : 0;
		$state = !empty($param['state']) ? $param['state'] : 0;

		if($eid == 0 || $jobid == 0 || $uid == 0 || $state == 0)
		{
			return false;	
		}

		$sql = "select id from e_resume_job_relation where uid={$uid} and firm_id={$eid} and job_id={$jobid}";
		$id = $db->getOne($sql);

		if(!empty($id)){
			$csql = "update e_resume_job_relation set state='{$state}' where uid={$uid} and firm_id={$eid} and job_id={$jobid}";
		}else{
			$csql = "insert into e_resume_state(uid, firm_id, job_id, state) values ({$uid},{$eid}, {$jobid}, {$state})";
		}

		$re = $db->query($csql);

		return $re;
	}	

}

?>
